package state.pattern;

/**
 * @author ZLL
 * @date create in 2018/05/10
 */
public class Account {

    private AccountState state;

    private String owner;

    private double balance = 0;

    public Account(String owner, double balance) {
        this.owner = owner;
        this.balance = balance;
        this.state = new NormalState(this);

        System.out.println(this.owner+"===>开户,初始金额额为==》"+this.balance);
    }


    public double getBalance() {
        return balance;
    }

    public void setState(AccountState state) {
        this.state = state;
    }


    /**
     *
     * @param amount
     */
    public void deposit(double amount){
        System.out.println(this.owner +"存款"+amount);

        state.depoise(getBalance() + amount);

        System.out.println("现在金额为==》"+this.balance);
        System.out.println("现在账户状态===》"+this.state.getClass().getName());
        System.out.println("=====================================");
    }

    public void withDraw(double amount){
        System.out.println(this.owner +"取款"+amount);

        state.withDraw(getBalance() - amount);

        System.out.println("现在金额为==》"+this.balance);
        System.out.println("现在账户状态===》"+this.state.getClass().getName());
        System.out.println("=============================================");

    }

    public void computerInterest(){
        state.computeInterest();
    }
}
